#ifndef DISPLAYWINDOW_H
#define DISPLAYWINDOW_H
#include <QMutex>
#include <QWidget>
#include "ffplay_stater.h"
//#include <a
#include <QPainter>
#include "imagescaler.h"
#include "picscAle.h"
#include "libavformat/avformat.h"
//#include "libavutil/avconfig.h"
//typedef struct VideoFrame
//{
//    uint8_t *data[8] = {NULL};         // 类似FFmpeg的buf, 如果是
//    int32_t linesize[8] = {0};
//    int32_t width;
//    int32_t height;
//    int format = AV_PIX_FMT_YUV420P;
//}VideoFrame;
namespace Ui {
class displaywindow;
}

class displaywindow : public QWidget
{
    Q_OBJECT

public:
    int Draw(const Frame *frame);
    void DeInit();
    void StartPlay();
    void StopPlay();
    explicit displaywindow(QWidget *parent = 0);
    ~displaywindow();
protected:
    // 这里不要重载event事件，会导致paintEvent不被触发
    void paintEvent(QPaintEvent *) override;
    void resizeEvent(QResizeEvent *event);
private:
    Ui::displaywindow *ui;
    int m_nLastFrameWidth; ///< 记录视频宽高
    int m_nLastFrameHeight;
    bool is_display_size_change_ = false;
//    picscale *img_scaler_ = NULL;
    int x_ = 0; //  起始位置
    int y_ = 0;
    int video_width = 0;
    int video_height = 0;
    int img_width = 0;
    int img_height = 0;
    int win_width_ = 0;
    int win_height_ = 0;
    bool req_resize_ = false;
    QImage img;
    VideoFrame dst_video_frame_;
    QMutex m_mutex;
    picscale *img_scaler_ = NULL;
//    ImageScaler *img_scaler_ = NULL;

    int play_state_ = 0;    // 0 初始化状态; 1 播放状态; 2 停止状态
};

#endif // DISPLAYWINDOW_H
